Hidden Values |
| HTML defines the tag input of type hidden to send text values from a web page to another web page. In database applications, hidden values allow moving a primary key value (or more values) from one web page to another during an SQL UPDATE or and SQL SELECT. |
| Tip |
In order for two pages to share a hidden variable:
|
| Problem 1 |
| Create a project called CateManagerWeb to edit and insert categories from a web application. Publish the web application to a web server using Anonymous Access. |
| Step A |
| Insert a Parent Node (a table). Then, insert a list view control. |


| Step B |
| Insert a button to insert categories. Set the button width to 100%. |

| Step C |
| Insert a button to edit categories. Set the button width to 100%. |

| Step D |
| Insert after the main table a hidden value to share the category_id between two web pages. |



| Step E |
| Add a new Web page Tools > Add Wintempla Item... > Web Page . In previous versions of Wintempla use: Project > Add New Item... > Wintempla Web Page . |
| Step F |
| Edit the CategoryPage web page as shown below. |


| Step G |
| Edit the CateManagerWeb.cpp file to include the CategoryPage.h file as shown below. |

| Step H |
| Edit the CategoryPage.h file as shown. |
| CategoryPage.h |
| #pragma once //_____________________________________________ CategoryPage.h #include "resource.h" class CategoryPage: public Web::Page { public: CategoryPage() { category_id = -1; } ~CategoryPage() { } int category_id; private: ... }; |
| Step I |
| Edit the CategoryPage.cpp file as shown. |
| CategoryPage.cpp |
| ... #include "stdafx.h" //_____________________________________________ CategoryPage.cpp #include "CategoryPage.h" //#include "CategoryPage.h" //<< ADD THIS LINE IN THE CateManagerWeb.cpp FILE void CategoryPage::Window_Open(Web::HttpConnector& h) { category_id = hdCategoryID; if (category_id < 0) return; //______________________________________________ 1. It is an INSERT, nothing to do if (h.FirstTime == true) { //__________________________________________________________________ 2. Create SELECT statement wstring cmd; Sys::Format(cmd, L"SELECT descr FROM category WHERE category_id = %d", category_id); //__________________________________________________________________ 3. Execute SELECT Sql::SqlConnection conn; try { //conn.OpenSession(DSN, USERNAME, PASSWORD); //Control Panel>Administrative Tools>Data Sources (ODBC)>Create dsn_myDatabase conn.OpenSession(NULL, CONNECTION_STRING); conn.ExecuteSelect(cmd); conn.BindColumn(1, tbxDescription, 64); if (conn.Fetch() == false) { this->MessageBox(L"No data was returned", L"Error", MB_OK | MB_ICONERROR); } } catch (Sql::SqlException e) { this->MessageBox(e.GetDescription(), L"Error", MB_OK | MB_ICONERROR); } } } void CategoryPage::btOK_onclick(Web::HttpConnector& h) { Sql::StringBuilder sb(L"category", L"category_id", category_id); sb.Bind(L"descr", tbxDescription); Sql::SqlConnection conn; int rows = 0; try { //conn.OpenSession(DSN, USERNAME, PASSWORD); //Control Panel>Administrative Tools>Data Sources (ODBC)>Create dsn_myDatabase conn.OpenSession(NULL, CONNECTION_STRING); rows = conn.ExecuteNonQuery(sb.GetString()); if (rows != 1) { this->MessageBox(Sys::Convert::ToString(rows), L"Error -number of rows", MB_OK | MB_ICONERROR); } } catch (Sql::SqlException e) { this->MessageBox(e.GetDescription(), L"Error", MB_OK | MB_ICONERROR); return; } h.NavigateTo(L"Index"); } void CategoryPage::btCancel_onclick(Web::HttpConnector& h) { h.NavigateTo(L"Index"); } |
| Step J |
| Edit the Index.h file as shown. |
| Index.h |
| #pragma once //_____________________________________________ Index.h #include "resource.h" class Index: public Web::Page { public: Index() { } ~Index() { } void UpdateListView(); private: ... }; |
| Step K |
| Edit the Index.cpp file as shown. |
| Index.cpp |
| ... void Index::Window_Open(Web::HttpConnector& h) { //________________________________________________________ 1. Column Setup lvCategory.Cols.Add(LVCFMT_LEFT, 20, L"Name"); UpdateListView(); } void Index::btInsert_onclick(Web::HttpConnector& h) { hdCategoryID = -1; h.NavigateTo(L"CategoryPage"); } void Index::btEdit_onclick(Web::HttpConnector& h) { LPARAM category_id; if (lvCategory.GetSelectedData(category_id) == false) return; hdCategoryID = (int)category_id; h.NavigateTo(L"CategoryPage"); } void Index::UpdateListView() { Sql::SqlConnection conn; try { //conn.OpenSession(DSN, USERNAME, PASSWORD); //Control Panel>Administrative Tools>Data Sources (ODBC)>Create dsn_myDatabase conn.OpenSession(NULL, CONNECTION_STRING); conn.ExecuteSelect(L"SELECT category_id, descr FROM category", 100, lvCategory); } catch (Sql::SqlException e) { this->MessageBox(e.GetDescription(), L"Error", MB_OK | MB_ICONERROR); } } |

